
package cn.chochy.my.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * 系统时间处理类
 *
 * @author MLeo
 */
public class DateUtil {

    /**
     * 获取当前系统时间
     *
     * @return String
     */
    public static String SystemDateTime() {
        Date d = new Date();
        String dateString = new SimpleDateFormat("yyyy-MM-dd H:mm:ss.S").format(d);
        return dateString;
    }

    public static String dateTimeFormat(String dateTime) {
        if (null != dateTime) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd H:mm:ss");
            try {
                Date date = sdf.parse(dateTime);
                dateTime = sdf.format(date);
            } catch (ParseException ex) {
                Logger.getLogger(DateUtil.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        return dateTime;
    }

    public static void main(String[] args) {
        String date = dateTimeFormat("2014-02-13 17:05:09.473");
        System.out.println(date);
    }
}
